package com.liuguang.framework.utils;

import android.annotation.TargetApi;
import android.content.res.Resources;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.google.android.material.tabs.TabLayout;

public class TabLayoutUtils {

    public static void setScaledTabLayout(final TabLayout tabLayout, final int i, final int i2, boolean z) {
        tabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @TargetApi(16)
            public void onGlobalLayout() {
                tabLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                LinearLayout linearLayout = (LinearLayout) tabLayout.getChildAt(0);
                int applyDimension = (int) TypedValue.applyDimension(1, (float) i, Resources.getSystem().getDisplayMetrics());
                int applyDimension2 = (int) TypedValue.applyDimension(1, (float) i2, Resources.getSystem().getDisplayMetrics());
                for (int i = 0; i < linearLayout.getChildCount(); i++) {
                    View childAt = linearLayout.getChildAt(i);
                    childAt.setPadding(0, 0, 0, 0);
                    LayoutParams layoutParams = new LayoutParams(0, -1, 1.0f);
                    layoutParams.leftMargin = applyDimension;
                    layoutParams.rightMargin = applyDimension2;
                    childAt.setLayoutParams(layoutParams);
                    childAt.invalidate();
                }
            }
        });
    }

    public static void setTabWidthSame(final TabLayout tabLayout) {
        tabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            /* JADX WARNING: Can't wrap try/catch for region: R(2:12|13) */
            /* JADX WARNING: Code restructure failed: missing block: B:13:?, code lost:
                r5 = r4.getClass().getDeclaredField("textView");
             */
            /* JADX WARNING: Code restructure failed: missing block: B:19:0x0062, code lost:
                r5 = e;
             */
            /* JADX WARNING: Code restructure failed: missing block: B:20:0x0063, code lost:
                r6 = 0;
             */
            /* JADX WARNING: Failed to process nested try/catch */
            /* JADX WARNING: Missing exception handler attribute for start block: B:12:0x003e */
            /* Code decompiled incorrectly, please refer to instructions dump. */
            public void onGlobalLayout() {
                /*
                    r7 = this;
                    android.support.design.widget.TabLayout r0 = r2
                    android.view.ViewTreeObserver r0 = r0.getViewTreeObserver()
                    r0.removeOnGlobalLayoutListener(r7)
                    android.support.design.widget.TabLayout r0 = r2
                    r1 = 0
                    android.view.View r0 = r0.getChildAt(r1)
                    android.widget.LinearLayout r0 = (android.widget.LinearLayout) r0
                    if (r0 != 0) goto L_0x0015
                    return
                L_0x0015:
                    int r2 = r0.getMeasuredWidth()
                    int r3 = r0.getChildCount()
                    if (r3 != 0) goto L_0x0020
                    return
                L_0x0020:
                    int r3 = r0.getChildCount()
                    int r2 = r2 / r3
                    r3 = 0
                L_0x0026:
                    int r4 = r0.getChildCount()
                    if (r3 >= r4) goto L_0x0081
                    android.view.View r4 = r0.getChildAt(r3)
                    r4.setPadding(r1, r1, r1, r1)
                    java.lang.Class r5 = r4.getClass()     // Catch:{ Exception -> 0x003e }
                    java.lang.String r6 = "mTextView"
                    java.lang.reflect.Field r5 = r5.getDeclaredField(r6)     // Catch:{ Exception -> 0x003e }
                    goto L_0x0048
                L_0x003e:
                    java.lang.Class r5 = r4.getClass()     // Catch:{ Exception -> 0x0062 }
                    java.lang.String r6 = "textView"
                    java.lang.reflect.Field r5 = r5.getDeclaredField(r6)     // Catch:{ Exception -> 0x0062 }
                L_0x0048:
                    r6 = 1
                    r5.setAccessible(r6)     // Catch:{ Exception -> 0x0062 }
                    java.lang.Object r5 = r5.get(r4)     // Catch:{ Exception -> 0x0062 }
                    android.widget.TextView r5 = (android.widget.TextView) r5     // Catch:{ Exception -> 0x0062 }
                    int r6 = r5.getWidth()     // Catch:{ Exception -> 0x0062 }
                    if (r6 != 0) goto L_0x0067
                    r5.measure(r1, r1)     // Catch:{ Exception -> 0x0060 }
                    int r5 = r5.getMeasuredWidth()     // Catch:{ Exception -> 0x0060 }
                    goto L_0x0068
                L_0x0060:
                    r5 = move-exception
                    goto L_0x0064
                L_0x0062:
                    r5 = move-exception
                    r6 = 0
                L_0x0064:
                    r5.printStackTrace()
                L_0x0067:
                    r5 = r6
                L_0x0068:
                    android.view.ViewGroup$LayoutParams r6 = r4.getLayoutParams()
                    android.widget.LinearLayout$LayoutParams r6 = (android.widget.LinearLayout.LayoutParams) r6
                    r6.width = r5
                    int r5 = r2 - r5
                    int r5 = r5 / 2
                    r6.leftMargin = r5
                    r6.rightMargin = r5
                    r4.setLayoutParams(r6)
                    r4.invalidate()
                    int r3 = r3 + 1
                    goto L_0x0026
                L_0x0081:
                    return
                */
                throw new UnsupportedOperationException("Method not decompiled: com.liuguang.framework.utils.TabLayoutUtils.AnonymousClass3.onGlobalLayout():void");
            }
        });
    }
}
